package ar.uba.fi.tp2Unit.framework;



import java.util.List;
import java.util.Observer;

import ar.uba.fi.tp2Unit.displayers.ConsoleTestResultDisplayer;


/**
 * It represents the entry point to the framework. In order to run a 
 * test, pass it to the runner along with a {@link TestResultDisplayable}
 * to see the results.  
 * 
 * @author grupo12
 * @see {@link Test}, {@link TestResultDisplayable}
 */
public class TestRunner {

	public static void run(Test test){
		TestRunner.run(test, new ConsoleTestResultDisplayer());
	}
	
	public static void run(Test test, TestResultDisplayable displayer){
		TestResult testResult = new TestResult();
		TestFixture testFixture = new TestFixture();
		if (displayer instanceof Observer){
			testResult.addObserver((Observer) displayer);
		}
		
		test.test(testResult, testFixture);
		
		testResult.stopMeasuringTime();
		displayer.display(testResult);		
	}
	
	public static void run(Test test, String pattern, TestResultDisplayable displayer){
		TestResult testResult = new TestResult();
		TestFixture testFixture = new TestFixture();
		if (displayer instanceof Observer){
			testResult.addObserver((Observer) displayer);
		}
		
		test.test(testResult, pattern, testFixture);
		
		testResult.stopMeasuringTime();
		displayer.display(testResult);		
	}
	
	public static void run(Test test, List<String> runTags, TestResultDisplayable displayer){
		TestResult testResult = new TestResult();
		TestFixture testFixture = new TestFixture();
		if (displayer instanceof Observer){
			testResult.addObserver((Observer) displayer);
		}		
		test.test(testResult, runTags, testFixture);
		
		testResult.stopMeasuringTime();
		displayer.display(testResult);		
	}
	
	public static void run(Test test, String pattern, List<String> tags, TestResultDisplayable displayer){
		TestResult testResult = new TestResult();
		TestFixture testFixture = new TestFixture();
		if (displayer instanceof Observer){
			testResult.addObserver((Observer) displayer);
		}
		
		test.test(testResult, pattern, tags, testFixture);
		
		testResult.stopMeasuringTime();
		displayer.display(testResult);		
	}
}
